package tj.eskhata.pos.examples;

import java.io.Serializable;
import java.math.BigDecimal;

import org.apache.wicket.PageParameters;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormValidatingBehavior;
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.Model;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.apache.wicket.util.time.Duration;
import org.hibernate.criterion.Expression;

import tj.eskhata.pos.domain.Client;
import tj.eskhata.pos.domain.Sost;
import tj.eskhata.pos.services.PosService;
import tj.eskhata.pos.*;
import tj.eskhata.pos.web.BasePage;


public class Page1 extends BasePage {
	private String str="This is in the subclass Page1";
	private String editor;
	@SpringBean
	private PosService service;
	
	public Page1() {
	
		final TextArea editor = new TextArea("editor", new Model( str));
		final Label lbl=new Label("label1", new Model()/*{
			@Override			
			public Object getObject() {				
				return editor.getModelObject();
			}
		}*/);
		lbl.setOutputMarkupId(true);
		
		
		add(lbl);
		Form form = new Form("form"){			
			@Override
	        public void onSubmit() {
				String value = (String) editor.getModelObject();
				//int i=Integer.parseInt(value);
				Sost cl=service.findByCriteria(Sost.class, Expression.eq("code", value)).get(0);//load(Client.class, i);
				lbl.setDefaultModelObject(cl.getId()+" "+cl.getName()); 
				editor.setDefaultModelObject("");
			}
        };
        //editor.setOutputMarkupId(true);
        form.add(editor);
        
        add(form);
        
        //AjaxFormValidatingBehavior.addToAllFormComponents(form, "onkeyup", Duration.ONE_SECOND);
        
        /*
        OnChangeAjaxBehavior onChangeAjaxBehavior = new OnChangeAjaxBehavior()
		{
			@Override
			protected void onUpdate(AjaxRequestTarget target)
			{
				lbl.setDefaultModelObject(editor.getDefaultModelObjectAsString());
				target.addComponent(lbl);
			}
		};		
		editor.add(onChangeAjaxBehavior);
        */
		
		//txtSumma.add(onChangeAjaxSumma);
		/*txtSumma.add(new AjaxFormComponentUpdatingBehavior("onblur"){
			@Override
			  protected void onUpdate(final AjaxRequestTarget target) {			    
			    txtComiss.setDefaultModelObject(txtSumma.getDefaultModelObjectAsString());
			    target.addComponent(txtComiss);
			  }

		});*/

	}
	
	private void setStr(String str)
	{
		this.str=str;
	}
	private String getStr()
	{
		return str;
	}
}
